package me.baicai.weixin.identity.repository;

import me.baicai.weixin.entity.gcb.Advertising;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface AdvertisingRepository extends JpaRepository<Advertising,Integer>
{

    Page<Advertising> findAllById(Integer id, Pageable pageable);

    @Query(value = "select * from advertising a where a.status = 0 and a.city like ?1 and a.region like ?2 and NOW() between  a.effectiveDate  and a.expiryDate ORDER BY rand() limit ?3", nativeQuery = true)
    List<Advertising> findAllByRegionLike(String city, String regin, Integer size);

    @Query(value = "select * from advertising a where a.status = 0 and a.shopid = ?1 and NOW() between  a.effectiveDate  and a.expiryDate ORDER BY rand() limit 4", nativeQuery = true)
    List<Advertising> findAllByShopId(Integer shopid);
}
